package com.andy.blog.dal.service.impl;

import com.andy.blog.dal.domain.GenTableDO;
import com.andy.blog.dal.mapper.GenTableMapper;
import com.andy.blog.dal.service.GenTableDalService;
import com.andy.blog.dal.vo.GenTableVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * Created by andy on 2023/7/16 10:20
 */
@Service
public class GenTableDalServiceImpl implements GenTableDalService {

    @Resource
    private GenTableMapper genTableMapper;


    @Override
    public IPage<GenTableDO> selectListByPage(GenTableVO genTableVO) {
        LambdaQueryWrapper<GenTableDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper
                .like(StringUtils.isNotBlank(genTableVO.getTableName()), GenTableDO::getTableName, genTableVO.getTableName())
                .like(StringUtils.isNotBlank(genTableVO.getTableComment()), GenTableDO::getTableComment, genTableVO.getTableComment())
                .ge(StringUtils.isNotBlank(genTableVO.getBeginTime()), GenTableDO::getCreateTime, genTableVO.getBeginTime())
                .le(StringUtils.isNotBlank(genTableVO.getEndTime()), GenTableDO::getCreateTime, genTableVO.getEndTime());

        IPage<GenTableDO> page = new Page<>(genTableVO.getPageNum(), genTableVO.getPageSize());
        return genTableMapper.selectPage(page, lambdaQueryWrapper);
    }

    @Override
    public List<GenTableDO> selectList(GenTableVO genTableVO) {
        LambdaQueryWrapper<GenTableDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Objects.nonNull(genTableVO.getTableName()), GenTableDO::getId, genTableVO.getId());

        return genTableMapper.selectList(lambdaQueryWrapper);
    }
}
